<template>
  <div>
    <group>
      <popup-radio title="厂站选择" v-model="state" :options="options">
        <popup-header slot="popup-header" title="请选择"></popup-header>
      </popup-radio>
    </group>
    <group>
      <datetime v-model="begin" title="开始日期" :end-date="end"></datetime>
    </group>
    <group>
      <datetime v-model="end" title="结束日期" :end-date="today"></datetime>
    </group>
    <table cellspacing="0">
      <thead>
      <tr>
        <th>序号</th>
        <th>时间</th>
        <th>描述</th>
      </tr>
      </thead>
      <tbody>
      <tr v-for="(item, key) in list" :key="key">
        <td>{{key + 1}}</td>
        <td>{{item.split(',')[0]}}</td>
        <td>{{item.split(',')[1]}}</td>
      </tr>
      </tbody>
    </table>
    <div v-show="list.length===0" class="tip">暂无数据</div>
  </div>
</template>

<script>
export default {
  name: 'AlarmList',
  data () {
    return {
      options: [],
      begin: '2020-02-01',
      end: '2020-02-04',
      list: [],
      today: '',
      state: ''
    }
  },
  methods: {
    search () {
      this.newProjectDwr.getRunLogAll(this.begin, this.end, [this.state], [], 'true', '-1', '', true, localStorage.userId, res => {
        if (res.length) {
          this.list = res
        }
      })
    },
    init () {
      var date = new Date()
      var year = date.getFullYear()
      var month = date.getMonth() + 1
      var day = date.getDate()
      month < 10 && (month = '0' + month)
      day < 10 && (day = '0' + day)
      this.today = this.end = `${year}-${month}-${day}`
      this.newProjectDwr.getSubstationList(res => {
        var list = res.split(',')
        const id = localStorage.scadaId
        const len = list.length
        var obj = []
        for (var i = 0; i < len; i = i + 2) {
          if (id.includes(list[i])) {
            if (!this.state) {
              this.state = list[i]
            }
            obj.push({ key: list[i], value: list[i + 1] })
          }
        }
        this.options = obj
      })
    }
  },
  created () {
    this.init()
  },
  watch: {
    state () {
      this.search()
    },
    begin () {
      this.search()
    },
    end () {
      this.search()
    }
  }
}
</script>

<style scoped>
.input{
  -webkit-appearance: none;
  outline: 0;
}
</style>
